package com.hams.demo.system.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.hams.demo.system.dao.DepartmentRepository;
import com.hams.demo.system.entity.Department;
import com.hams.demo.system.entity.dto.DepartmentDTO;

@Service
@Transactional
public class DepartmentService implements IDepartmentService {
	
	@Autowired
	private DepartmentRepository departmentRepository;
	
	public void saveOrUpdate(Department department) {
		departmentRepository.save(department);
	}
	
	public void delete(Department department) {
		departmentRepository.delete(department);
	}

	public void delete(List<Long> ids) {
		List<Department> Departments = (List<Department>) departmentRepository.findAll(ids);
		if(Departments!=null) {
			departmentRepository.delete(Departments);
		}
		
	}

	@Transactional(readOnly = true)
	public Department findOne(Long id) {
		return departmentRepository.findOne(id);
	}

	@Transactional(readOnly = true)
	public List<Department> findAll() {
		return (List<Department>) departmentRepository.findAll();
	}

	@Transactional(readOnly = true)
	public Page<Department> findAll(Specification<Department> spec, Pageable pageable) {
		return departmentRepository.findAll(spec, pageable);
	}

	@Transactional(readOnly = true)
	public Department findDepartment(String name) {
		return departmentRepository.findDepartment(name);
	}

	@Override
	public boolean exist(Long id) {
		return departmentRepository.exists(id);
	}

}
